package com.ssn.iterator;

import java.util.ArrayList;

public class MyIterator<T> implements Iterator{
    private ArrayList<T> arrayList;
    public MyIterator(Aggregate aggregate) {
        this.arrayList = aggregate.getAggregate();
    }

    @Override
    public void forwardTravel() {
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            System.out.print(arrayList.get(i) + (i == size - 1 ? "" : " "));
        }
    }

    @Override
    public void reverseTravel() {
        int size = arrayList.size();
        for (int i = size - 1; i >= 0 ; i--) {
            System.out.print(arrayList.get(i) + (i == 0 ? "" : " "));
        }
    }
}
